package com.adl.hotelmanage.servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.adl.hotelmanage.dao.DbInquire;
import com.adl.hotelmanage.po.RoomInfo;

/**
 * Servlet implementation class RoomShowServlet
 */
@WebServlet("/RoomShowServlet")
public class RoomShowServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RoomShowServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
//		List<RoomInfo> roomshowls = new ArrayList<RoomInfo>();
		String sql = "select * from t_roominfo where roominfo_roomId="+"'"+request.getParameter("roomid")+"';";
		ResultSet roomshowrs = DbInquire.inquire(sql);
		System.out.println(roomshowrs);
		try {
			while (roomshowrs.next()) {
				RoomInfo roominfo = new RoomInfo();
				roominfo.setRoomid(roomshowrs.getString("roominfo_roomId"));
				roominfo.setRoomtype(roomshowrs.getString("roominfo_roomtype"));
				roominfo.setState(roomshowrs.getString("roominfo_state"));
				roominfo.setLocation(roomshowrs.getString("roominfo_location"));
				roominfo.setNote(roomshowrs.getString("roominfo_note"));
				roominfo.setBednum(Integer.parseInt(roomshowrs.getString("roominfo_bednum")));
				roominfo.setPrice(Integer.parseInt(roomshowrs.getString("roominfo_price")));
//				roomshowls.add(roominfo);
//				request.setAttribute("roomshowlist",roomshowls);
				request.setAttribute("roominfo",roominfo);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		request.getRequestDispatcher("room-show.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		
	}

}
